﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using ScrumTable.Config.ConfigManagement;
using ScrumTable.BL.DM.DataManagement;
using ScrumTable.Config.UserManagement;
using ScrumTable.UI.ViewModel.Controller;
using Microsoft.Practices.Unity;
using ScrumTable.UI.ViewModel.Data;
using ScrumTable.UI.ViewModel.Extension; 

#endregion

namespace ScrumTable.UI.ViewModel.View
{
    /// <summary>
    /// Description of the class
    /// </summary>
    public class ConfigSettingViewModel : ViewModelBase
    {
 
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------
        
        private ScrumViewModelData _scrumData;
   
        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------  

        /// <summary>
        /// Gets or sets the scrum data.
        /// </summary>
        /// <value>The scrum data.</value>
        [Dependency]
        public ScrumViewModelData ScrumData
        {
            get { return _scrumData; }
            set
            {
                _scrumData = value; 
            }
        }


        /// <summary>
        /// ConfigManager
        /// </summary>
        [Dependency]
        public ConfigManager ConfigManager { get; set; }

        /// <summary>
        /// LoginAccountManger
        /// </summary>
        [Dependency]
        public LoginAccountManager LoginAccountManager { get; set; }

        /// <summary>
        /// CurrentConfig
        /// </summary>
        public Config.ConfigManagement.Config CurrentConfig
        {
            get { return ConfigManager.Config; }
            set
            {
                ConfigManager.Config = value;
                if (value != null)
                {
                    LoginAccountManager.CurrentLoginAccount.ConfigId = value.Id;
                }
                SendPropertyChanged("CurrentConfig");
            }
        }


        /// <summary>
        /// ConfigList
        /// </summary>
        public ObservableCollection<Config.ConfigManagement.Config> ConfigList
        {
            get { return new ObservableCollection<Config.ConfigManagement.Config>(ConfigManager.ConfigList); }
        }



        public bool InWizardMode
        {
            get { return NaviController.CurrentTarget.IsWizardTarget(); }
        }
       

      
        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Adds a new Config
        /// </summary>
        public void AddNewConfig(string name=null)
        {
            ConfigManager.AddAndSetConfig(name);
            CurrentConfig = ConfigManager.Config;
            SendPropertyChanged("ConfigList");
        }

        /// <summary>
        /// delets the config
        /// </summary>
        public void DeleteConfig(ScrumTable.Config.ConfigManagement.Config toDelete)
        {
            if (CanDeleteConfig(toDelete))
            {
                ConfigManager.DeleteConfig(toDelete);
                SendPropertyChanged("ConfigList");
            }
        }

        /// <summary>
        /// Checks if the given config can be deleted
        /// </summary>
        public bool CanDeleteConfig(Config.ConfigManagement.Config toDelete)
        {
            return ConfigManager.Config != toDelete;
        }

        /// <summary>
        /// Sets a new Config for a list of screenNames
        /// </summary>
        /// <param name="screenNames">list of screenNames</param>
        public void SetNewConfig(List<string> screenNames)
        {
            ConfigManager.AddScreenSettings(screenNames);
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------


        #endregion
    }
}